<?php
/**
 * Created by PhpStorm.
 * @description:
 * @time:
 * @Author: yfl
 * @QQ 554665488
 * Date: 2018-5-28
 * Time: 12:08
 */
$serverA = new Swoole\Server('127.0.0.1', 9502, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);
$serverA->set([
    'worker_num' => 2
]);

//监听连接进入事件,有客户端连接进来的时候会触发
$serverA->on('connect', function ($serv, $fd) {
    echo "有新的客户端连接，连接标识为$fd" . PHP_EOL;
});


//监听数据接收事件,server接收到客户端的数据后，worker进程内触发该回调
$serverA->on('receive', function ($serv, $fd, $from_id, $data) {

    $serv->send($fd, "服务器B处理完返回给服务器A的客户端: ".$data);
});


//监听连接关闭事件,客服端关闭，或者服务器主动关闭
$serverA->on('close', function ($serv, $fd) {
    echo "编号为{$fd}的客户端已经关闭.".PHP_EOL;
});


//启动服务器
$serverA->start();

